package com.zto.sch.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2020-12-24 15:40
 **/
public class MobileJsonSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        //手机号脱敏
        String afterStr = s.replaceAll("(\\d{3})\\d+(\\d{4})", "$1****$2");

        jsonGenerator.writeString(afterStr);
    }
}
